package com.easy.neo4j.repository;
import com.easy.neo4j.entry.PowerBike;
import com.easy.neo4j.statistics.PowerBikeStatistics;
import org.apache.ibatis.annotations.Result;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-03-26 13:46
 **/
@Repository
public interface PowerBikeRepository extends Neo4jRepository<PowerBike, Long> {
    @Query("MATCH ({name:$parkName})-[:Bike]->(bike:PowerBike) " +
            "RETURN bike")
    List<PowerBike> findBikeByParkName(@Param("parkName") String parkName);

    @Query("CREATE (node:PowerBike {" +
            "bikeModel: $bikeMode," +
            "bike_plateform: $platfrom," +
            "c_bikelat: $lat," +
            "c_bikelong: $lng," +
            "c_bikeno:$bikeno," +
            "c_citycode: $cityCode," +
            "c_state: '0'," +
            "mileage: $mileage," +
            "power: $power," +
            "pic: $pic " +
            "})" +
            "WITH node " +
            "MATCH (p:Park {name:$parkName}) " +
            "WITH p,node " +
            "CREATE (p)-[:Bike]->(node)")
    void addBike(@Param("pic") String pic, @Param("bikeMode") String bikeMode, @Param("platfrom") String platfrom, @Param("lat") String lat, @Param("lng") String lng, @Param("bikeno") String bikeno, @Param("cityCode") String cityCode, @Param("mileage") String mileage, @Param("power") String power, @Param("parkName") String parkName);

    @Query("MATCH ()-[r:Bike]->(bike:PowerBike {c_bikeno:$bikeNo}) DELETE r,bike")
    void deleteBike(@Param("bikeNo") String bikeNo);

    @Query("MATCH (p)-[:Bike]->(n:PowerBike) " +
            "WHERE p.name = $parkName AND n.bike_plateform CONTAINS $platform AND n.c_bikeno CONTAINS $info AND n.mileage>$startMileage AND n.mileage<$endMileage " +
            "RETURN n")
    List<PowerBike> detailedQueryOfBicycleInformation(@Param("parkName") String parkName, @Param("info") String info, @Param("startMileage") String startMileage, @Param("endMileage") String endMileage, @Param("platform") String platform);

    @Query("MATCH (p:PowerBike) " +
            "WITH p.bike_plateform AS plateform " +
            "RETURN plateform,COUNT(*) AS count ")
    List<Object> getPlatformInfo();
}
